import { RuleItem } from './types/rule'
import { CSSProperties } from 'vue'

import { ValidateFieldsError } from 'async-validator'
interface Callback {
  (isValid?: boolean, invalidFields?: ValidateFieldsError): void,
}

export interface FormOptions {
  type: 'input' | 'radio' | 'radioGroup' | 'checkbox' | 'checkboxGroup' |
  'select' | 'selectGroup' | 'option' | 'datePicker' | 'timePicker' | 'dateTimePicker' | 'rate' | 'slider' | 'switch' | 'upload' | 'colorPicker' | 'cascader' | 'transfer' | 'inputNumber' | 'textArea' | 'custom',
  label?: string,
  value?: any,
  prop?: string,
  rules?: RuleItem[],
  attrs?: {
    clearable?: boolean,
    showPassword?: boolean,
    disabled?: boolean,
    style?: CSSProperties,
    format?: Date
  },
  placeholder?: string,
  children?: FormOptions[]
}

export interface ValidateFieldCallback {
  (message?: string, invalidFields?: ValidateFieldsError): void,
}

export interface FormInstance {
  registerLabelWidth(width: number, oldWidth: number): void,
  deregisterLabelWidth(width: number): void,
  autoLabelWidth: string | undefined,
  emit: (evt: string, ...args: any[]) => void,
  labelSuffix: string,
  inline?: boolean,
  model?: Record<string, unknown>,
  size?: string,
  showMessage?: boolean,
  labelPosition?: string,
  labelWidth?: string,
  rules?: Record<string, unknown>,
  statusIcon?: boolean,
  hideRequiredAsterisk?: boolean,
  disabled?: boolean,
  validate: (callback?: Callback) => Promise<boolean>,
  resetFields: () => void,
  clearValidate: (props?: string | string[]) => void,
  validateField: (props: string | string[], cb: ValidateFieldCallback) => void,
}